"""
Copyright (c) 2022 Huawei Technologies Co.,Ltd.

openGauss is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:

          http://license.coscl.org.cn/MulanPSL2

THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
"""
"""
Case Type   : 服务端工具
Case Name   : gs_encrypt工具加密，待加密字符串前加在规定参数列表中的参数，参数后
              不加参数值
Create At   : 2021/11/25
Owner       : opentestcase004
Description :
    1.执行命令:
      gs_encrypt -k [用户输入的口令] -v [用户输入的盐值] -f [待加密明文字符串]
      加密明文字符串，待加密字符串前加在规定参数列表中的参数，参数后不加参数值
Expect      :
    1.执行失败，报错提示字符串前加的参数缺少参数值
History     :
"""

import unittest
from yat.test import Node
from yat.test import macro
from testcase.utils.Logger import Logger


class Tools(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.logger.info('Opengauss_Function_Tools_gs_encrypt_Case0028 start')
        self.dbuserNode = Node('PrimaryDbUser')

    def test_gs_encrypt(self):
        self.logger.info('----------进行加密操作----------')
        step = "step1:执行命令，加密明文字符串，待加密明文字符串前加在规定参数" \
               "列表中的参数，参数后不加参数值   except:执行失败，报错提示字符" \
               "串前加的参数缺少参数值"
        self.logger.info(step)
        str1 = 'test'
        encrypt = 'jj55##GG'
        vec = 'hhhhhhhhhhhhhhhh'
        check_cmd1 = f'''source {macro.DB_ENV_PATH};
            gs_encrypt  -k {encrypt} -v {vec} -f {str1}'''
        self.logger.info(check_cmd1)
        msg1 = self.dbuserNode.sh(check_cmd1).result()
        self.logger.info("---------加密结果--------")
        self.logger.info(msg1)
        self.assertIn('gs_encrypt: options PLAINTEXT must be input and it'
                      ' is not null', msg1, "执行失败" + step)

    def tearDown(self):
        self.logger.info('--------无需清理环境---------')
        self.logger.info('Opengauss_Function_Tools_gs_encrypt_Case0028 finish')
